import josx.rcxcomm.*;

import java.io.*;

/** For use on the PC for sending a byte to the RCX Read.java example
 * Compile using javac with pcrcxcomm.jar on the CLASSPATH
 */
public class PathSender {
  public static void main(String [] args) throws IOException {
	  try {
		  	if(args.length!=1)
				throw new Exception("first argument must be tower port (USB,COM1 etc)");
		    RCXPort port = new RCXPort("usb");
		    OutputStream out = port.getOutputStream();
			
            String pathData = args[0];
			
			String[] tokens = pathData.split(";");
			
			char[] data = new char[1000];
			/*data[0] = 190;
			data[1] = 175;
			
			data[2] = 50;
			data[3] = 0;
			
			data[4] = 175;
			data[5] = 150;*/
			
			int dataLength = 0;
			
			for (int i = 0 ; i < tokens.length ; i++) {
				String[] subtokens = tokens[i].split(",");
				//System.out.println(subtokens.length);
				int val = Integer.valueOf(subtokens[0]);
				data[dataLength] = (char)val;
				val = Integer.valueOf(subtokens[1]);
				data[dataLength + 1] = (char)val;
				dataLength += 2;
			}
			
			System.out.println(dataLength);
			
			data[dataLength] = 255;
			dataLength++;
			
			for (int i = 0 ; i < dataLength ; i++) {
				System.out.print((int)data[i] + " ");
			}
			
			out.flush();
			System.out.println(dataLength);
			for (int i = 0 ; i < dataLength ; i++) {
				System.out.println((int)data[i]);
				out.write(data[i]);
			}
		  } catch(Exception exc) {
			  //exc.printStackTrace();
		  }
  }
}

